package com.ruoyi.basicData.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicData.domain.Tbrole;
import com.ruoyi.basicData.service.ITbroleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 身份管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/tbrole/tbrole")
public class TbroleController extends BaseController
{
    @Autowired
    private ITbroleService tbroleService;

    /**
     * 查询身份管理列表
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tbrole tbrole)
    {
        startPage();
        List<Tbrole> list = tbroleService.selectTbroleList(tbrole);
        return getDataTable(list);
    }

    /**
     * 导出身份管理列表
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:export')")
    @Log(title = "身份管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tbrole tbrole)
    {
        List<Tbrole> list = tbroleService.selectTbroleList(tbrole);
        ExcelUtil<Tbrole> util = new ExcelUtil<Tbrole>(Tbrole.class);
        util.exportExcel(response, list, "身份管理数据");
    }

    /**
     * 获取身份管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return success(tbroleService.selectTbroleByRoleId(roleId));
    }

    /**
     * 新增身份管理
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:add')")
    @Log(title = "身份管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tbrole tbrole)
    {
        return toAjax(tbroleService.insertTbrole(tbrole));
    }

    /**
     * 修改身份管理
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:edit')")
    @Log(title = "身份管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tbrole tbrole)
    {
        return toAjax(tbroleService.updateTbrole(tbrole));
    }

    /**
     * 删除身份管理
     */
    @PreAuthorize("@ss.hasPermi('tbrole:tbrole:remove')")
    @Log(title = "身份管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(tbroleService.deleteTbroleByRoleIds(roleIds));
    }
}
